package com.xyhy.starter.security.handler;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import com.xyhy.core.utils.web.ServletUtils;
import com.xyhy.core.web.model.wrapper.Result;
import com.xyhy.core.web.model.wrapper.ResultCode;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
  @Override
  public void commence(HttpServletRequest request, HttpServletResponse response,
                       AuthenticationException authException) throws IOException, ServletException {
    ServletUtils.responsePrint(response, Result.fail(ResultCode.UN_AUTHORIZED, authException));
  }
}
